Skip to content

Comments

Add FTPS with SSL/TLS configuration#1522

Closed
YasanPunch wants to merge 37 commits intoballerina-platform:masterfrom
YasanPunch:add-ftps
Closed

Add FTPS with SSL/TLS configuration#1522
YasanPunch wants to merge 37 commits intoballerina-platform:masterfrom
YasanPunch:add-ftps

Conversation

@YasanPunch
Copy link
Contributor

Purpose


Fixes: ballerina-platform/ballerina-library/#8489

Adds FTPS (FTP over SSL/TLS) support to the FTP module, enabling secure file transfers using SSL/TLS certificates and encrypted data channels.

Changes:

  • Added FTPS protocol option to the Protocol enum.
  • Added SecureSocket configuration record for FTPS SSL/TLS settings.
  • Added FtpsMode enum to support IMPLICIT and EXPLICIT FTPS modes.
  • Added FtpsDataChannelProtection enum to control data channel encryption (PROT P/C/S/E)

API Changes:

public enum Protocol {
    FTP = "ftp",
    FTPS = "ftps",  // New: Secure File Transfer Protocol
    SFTP = "sftp"
}

# FTPS connection mode
public enum FtpsMode {
    IMPLICIT,   // SSL/TLS established immediately (typically port 990)
    EXPLICIT    // Upgrades to SSL/TLS via AUTH TLS (typically port 21)
}

# FTPS data channel protection level
public enum FtpsDataChannelProtection {
    CLEAR,          // PROT C - Clear/Unencrypted data channel
    PRIVATE,        // PROT P - Encrypted data channel (Default/Recommended)
    SAFE,           // PROT S - Integrity protected
    CONFIDENTIAL    // PROT E - Confidentiality protected
}

# Secure socket configuration for FTPS
public type SecureSocket record {|
    crypto:KeyStore key?;       // Client certificate/key
    crypto:TrustStore cert?;    // Server certificate/truststore
    FtpsMode mode = EXPLICIT;
    FtpsDataChannelProtection dataChannelProtection = PRIVATE;
|};

public type AuthConfiguration record {|
    // ... existing fields ...
    SecureSocket secureSocket?;  // New: For FTPS protocol
|};

(Current) Usage Example:

ftp:ClientConfiguration ftpsConfig = {
    protocol: ftp:FTPS,
    host: "ftps.example.com",
    port: 21,
    auth: {
        credentials: {username: "user", password: "pass"},
        secureSocket: {
            key: {path: "client.p12", password: "keypass"},
            trustStore: {path: "truststore.p12", password: "trustpass"},
            mode: ftp:EXPLICIT
        }
    }
};

Usage Example

ftp:ClientConfiguration ftpsConfig = {
protocol: ftp:FTPS,
host: "ftps.example.com",
port: 21,
auth: {
credentials: {username: "user", password: "pass"},
secureSocket: {
key: {path: "client.p12", password: "keypass"},
cert: {path: "truststore.p12", password: "trustpass"},
mode: ftp:EXPLICIT,
dataChannelProtection: ftp:PRIVATE
}
}
};

Future Enhancements (TODO):

  • [Hostname verification toggle for enhanced security (Currently handled by default VFS/JSSE behavior).

Checklist

  • Linked to an issue
  • Updated the changelog
  • Added tests (Client, Listener, and Configuration tests added.)
  • Updated the spec
  • Checked native-image compatibility

Yasan and others added 30 commits December 7, 2025 14:50
… 990 for IMPLICIT FTPS if unspecified. Improved KeyStore loading from Ballerina records and error handling for secure socket configurations.
…improved error handling for KeyStore loading, and added documentation regarding the limitations of hostname verification support.
…r implementations, as it is not supported by the current version of Apache Commons VFS2. Clean up related code and constants.
… configuration

- Introduced tests for FTPS client operations including explicit and implicit modes, file handling, and error scenarios.
- Added tests for FTPS listener functionality, ensuring correct event handling for file changes.
- Improved error handling for secure socket configurations in both client and server implementations.
- Updated mock server utilities to include FTPS server initialization for testing purposes.
… relevant files for consistency,

, remove hardcoded credentials and enhance password handling for improved security.
- Refactored test structure for better isolation and clarity.
- Introduced helper functions for state management and event handling.
- Improved file handling in tests, ensuring robust cleanup and setup.
- Updated mock server utilities to ensure isolated test environments for FTPS operations.
…ments

- Introduced a new configuration for testing the default port logic, ensuring that port 21 is correctly swapped to 990 for implicit mode.
- Added a cleanup function to manage test environment state after execution.
- Enhanced existing test cases to validate the new configuration and ensure robust error handling during FTPS operations.
- Updated the FTPS client test to use a more descriptive variable name for error handling.
- Increased the wait count in listener tests to ensure proper event detection.
- Improved error message clarity for invalid truststore scenarios in tests.
- Adjusted the FtpClient to default to port 990 when port 21 is specified for implicit FTPS mode.
@sonarqubecloud
Copy link

@YasanPunch YasanPunch closed this Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose FTPS as separate protocol when connecting to FTP server

2 participants